package service;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import util.MybatisUtil;

import dao.BranchesDao;
import dao.BranchesMapper;
import dao.WorkingMapper;
import entity.Branches;
import entity.Working;

public class BranchesService {
	BranchesDao branchesDao=new BranchesDao();
	
	/**
	 * ��ѯ���������Ϣ�ķ���
	 * @return ���������Ϣ����
	 */
	//List<Branches> queryAllBranches
	public List<Branches> queryAllBranches(){
		SqlSession sqlSession = null;
		List<Branches> list = new ArrayList<Branches>();
		try {
			
			sqlSession = MybatisUtil.createSqlSession();
			
			list = sqlSession.getMapper(BranchesMapper.class).queryAllBranches();
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
	/**
	 * ���id��ѯָ�������Ϣ
	 * @param id �����
	 * @return ָ��������
	 */
	public Branches queryBranchesById(int id) {
		SqlSession sqlSession = null;
		List<Branches> list = new ArrayList<Branches>();
		int count = 0;
		try {
			
			sqlSession = MybatisUtil.createSqlSession();
			
			//count = 
			sqlSession.getMapper(BranchesMapper.class).queryBranchesById(id);
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
	/**
	 * ���Ӫҵִ�պŲ�ѯָ�������Ϣ
	 * @param businessNo Ӫҵִ�պ�
	 * @return �����Ϣ����
	 */
	public Branches queryBranchesByBusNo(String businessNo) {
		SqlSession sqlSession = null;
		try {
			
			sqlSession = MybatisUtil.createSqlSession();
			
			//count = 
			sqlSession.getMapper(BranchesMapper.class).queryBranchesByBusNo(businessNo);
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
	/**
	 * ����µ������Ϣ�ķ�����
	 * @param branch �����������
	 * @return ��Ӱ������
	 */
	public int addBranch(Branches branch) {
		SqlSession sqlSession = null;
		int count = 0;
		try {
			sqlSession = MybatisUtil.createSqlSession();
			
			
			count = sqlSession.getMapper(BranchesMapper.class).addBranch(branch);
			
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
}
